/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package perso;

import carte.Carte;
import ctrl.AbstractFactory;
import ctrl.command.CmdConvert;
import ctrl.command.CmdKill;
import ctrl.command.CmdMove;
import ctrl.command.Command;
import java.util.ArrayList;

/**
 *
 * @author Vincent
 */
public class Agent extends PersonnageTruand {

    public Agent(int id, Carte carte) {
        super(id, carte);
        setImage("/images/agent.jpg");
        name = "Agent";
    }

    @Override
    public Command doAction() {
        Command cmd = new CmdMove(this, px, py);
        int lower = 1;
        int higher = 5;
        int random = (int) (Math.random() * (higher - lower)) + lower;
        int pxDest = px;
        int pyDest = py;
        if (random == 1) {
            if (px + 1 < carte.getPerso().length) {
                pxDest++;
            }
        } else if (random == 2) {
            if (px - 1 > 0) {
                pxDest--;
            }
        } else if (random == 3) {
            if (py - 1 > 0) {
                pyDest--;
            }
        } else if (random == 4) {
            if (py + 1 < carte.getPerso()[0].length) {
                pyDest++;

            }
        }
        Personnage cible = carte.getPerso()[pxDest][pyDest];
        if (cible == null) {
            if (carte.getPosObj()[pxDest][pyDest] != AbstractFactory.staticObj.PLANQUE) {
                cmd = new CmdMove(this, pxDest, pyDest);
            }
        } else if (cible instanceof Chef) {
            cmd = new CmdKill(this);
        } else if (cible instanceof Truand) {
            if (!((Truand) cible).isTaupe) {
                cmd = new CmdKill(cible);
            }
        }
        return cmd;
    }

    @Override
    public void convert(ArrayList<Personnage> listPerso) {
        throw new UnsupportedOperationException("Not supported yet.");
    }




}
